<template>
  <div class="myshopping">
    <!-- 轮播图 -->
    <div class="banner"></div>
    <!-- 商品陈列 -->
    <div class="content">
      <!-- 热卖商品 -->
      <div class="hot">
        <h3>热卖商品</h3>
        <div class="hotList">
          <ul>
            <li v-for="(item, i) of order" :key="i">
              <div>
                <!-- 图片 -->
                <img :src="item.o_img" alt="" />
                <!-- 热卖商品列表 -->
                <div class="inro">
                  <h3>{{ item.otitle }}</h3>
                  <p>{{ item.o_introduct }}</p>
                  <div class="price">
                    <span>{{ parseInt(item.o_price) }}</span
                    ><span>环保金</span>
                  </div>
                  <router-link :to="`/order/${item.o_id}`">
                    <button>立即兑换</button>
                  </router-link>
                </div>
              </div>
            </li>
          </ul>
        </div>
      </div>
      <!-- 新品待售 -->
      <div class="sale">
        <h3>新品待售</h3>
        <!-- 定时器 -->
        <div style="position: absolution; top: 0; right:0; color:red" class="itime">
        <span class="el-icon-time">待售商品倒计时:{{timeDate}}时{{ timeDay }}分{{ time }}秒</span>
       </div>
        <ul class="saleList">
          <li v-for="(p, r) of sale" :key="r">
            <div class="i">敬请期待</div>
            <img :src="`${p.gimg}`" alt="" />
            <h3>{{ p.gtitle }}</h3>
            <div class="price">
              <span>{{ p.g_price }}</span
              >环保金
            </div>
          </li>
        </ul>
      </div>
    </div>
  </div>
</template>
<script>
export default {
  data() {
    return {
      order: [],
      sale: [],
      // 定时器所需要的变量
      newTime: '2021-8-30 16:12:00',
      timeOut: '',
      timeSave: '',
      time: '',
      timeDay: '',
      timeDate:''
    };
  },
  methods: {
    saleProduct() {
      this.axios.get("/v1/products/sell").then((res) => {
        console.log(res.data.data);
        this.sale = res.data.data;
        console.log(this.sale);
      });
    },
    // 定时器
    setTime() {
      this.timeOut = setInterval(() => {
        setTimeout(() => {
          //newtime是倒计时的结束时间，当前时间和newTime指定的时间相同时，倒计时为0，即倒计时结束
          const timedate = new Date(this.newTime)
          const now = new Date()
          const date = timedate.getTime() - now.getTime()
          const time = Math.ceil(date / 1000) % 60//秒
          const timeDay = Math.ceil(date / (1000 * 60))%60//分钟
          const timeDate =Math.ceil(date/(1000*60*60))%24//小时
          // console.log(this.timeDate);
          this.time = time > 0 ? time : 0
          this.timeDay = timeDay > 0 ? timeDay : 0
          this.timeDate = timeDate > 0 ? timeDate : 0
        }, 0)
      }, 1000)
    },
  },
  mounted() {
    // 热卖商品列表
    this.axios.get("/v1/products/order").then((res) => {
      // console.log(res.data.data);
      this.order = res.data.data;
      console.log(this.order);
    });
    this.saleProduct();
    // 定时器
    this.setTime();
  },
};
</script>
<style lang="scss">
.myshopping {
  background-color: #f6f6f6;
  //    轮播图
  .banner {
    background-image: url(/img/shoppingcenter/banner.jpg);
    width: 100%;
    height: 400px;
    background-repeat: no-repeat;
    background-size: cover;
    background-position: center;
  }
  //商品陈列
  .content {
    width: 100%;
    padding-top: 54px;
    padding-bottom: 80px;
    //  热卖商品
    .hot {
      width: 1200px;
      margin: 0 auto;

      h3 {
        text-align: center;
        font-size: 24px;
        color: #333;
        height: 36px;
        line-height: 36px;
      }
      .hotList {
        width: 1200px;
        height: 648px;
        ul {
          list-style: none;
          overflow: hidden;
          :nth-child(odd) {
            margin-right: 15px;
          }
          li {
            padding: 40px;
            margin-top: 30px;
            //   margin-left: 15px;
            width: 505px;
            height: 214px;
            background-color: #fff;
            border-radius: 10px;
            float: left;
            // > div {
            //   width: 505px;
            //   height: 214px;
            //   color: #fff;
            //   padding:40px
            img {
              width: 280px;
              height: 214px;
              border-radius: 10px;
              display: block;
              float: left;
              margin-right: 30px;
            }
            .inro {
              width: 195px;
              height: 214px;
              float: left;
              h3 {
                font-size: 24px;
                height: 36px;
                text-align: left;
              }
              p {
                font-size: 14px;
                color: #666;
                margin-top: 8px;
                height: 40px;
              }
              .price {
                color: #ffc802;
                :nth-child(1) {
                  font-weight: 700;
                  font-size: 30px;
                  margin-right: 4px;
                }
              }
              & button {
                // text-decoration: none;
                width: 152px;
                height: 42px;
                color: #fff;
                background-color: #ffc802;
                color: #000;
                border: none;
                border-radius: 5px;
                margin-top: 27px;
              }
            }
            // }
          }
        }
      }
    }
    // 待售商品
    .sale {
      width: 1200px;
      margin: 0 auto;
      margin-top: 54px;
      position:relative;

      h3 {
        text-align: center;
        font-size: 24px;
        color: #333;
        height: 36px;
        line-height: 36px;
      }
      .itime{
        width: 300px;
        height: 30px;
        border:1px solid #ffc802;
        background-color: #ffc802;
        .el-icon-time{
          line-height: 30px;
          font-size: 20px;
          font-weight: 700;
        }
      }
      .saleList {
        width: 1200px;
        height: 1338px;

        margin: 0 auto;
        list-style: none;

        li {
          width: 370px;
          height: 420px;
          background-color: #fff;
          float: left;
          margin: 26px 30px 0 0;
          border-radius: 5px;
          .i {
            width: 80px;
            height: 24px;
            line-height: 24px;
            background-color: #ffc802;
            text-align: center;
            font-size: 12px;
            color: #fff;
            border-radius: 2px;
            margin: 0 auto;
          }
          img {
            display: block;
            width: 288px;
            height: 215px;
            margin: 0 auto;
            margin-top: 45px;
          }
          h3 {
            text-align: center;
            font-size: 24px;
            height: 36px;
            line-height: 36px;
            color: #333;
            margin-top: 25px;
          }
          .price {
            color: #ffc802;
            text-align: center;
            margin-top: 10px;
            span {
              font-weight: 700;
              font-size: 30px;
              margin-right: 4px;
            }
          }
        }
      }
    }
  }
}
</style>